<?php


namespace App\Models\Tool;


use Illuminate\Support\Facades\File;

/**创建添加魔板页面
 * Class MakeAddHtml
 * @package App\Models\Tool
 */
class MakeInfoHtmlAndJs
{

    static function make($html_file,$html_filename,$js_file,$js_filename){
/*
        [
            "fied" => "title"
    "type" => "input"
    "title" => "权限节点名称"
    "checktype" => null
  ]*/

        self::make_html($html_file,$html_filename,$js_file,'');
        self::make_js($js_file,$js_filename,'');

  }


    /**生成html
     * @param $html_file
     * @param $html_filename
     * @param $js_file
     * @param $middhtml
     */
  private static function make_html($html_file,$html_filename,$js_file,$middhtml){

      $js_file=str_replace('\\','/',$js_file).'?'.date('Y_m_d_H_i_s');
      $makecontent=<<<text
@extends('admin.defaults.head')
@section('title','标题')
@section('body')

{{--请在下面编辑body 内容--}}

<h1>详情页请自行编辑：以下为已读可以数据
</h1>
@{{\$data}}}=
{{var_dump(\$data)}}

{{--上方body内容结束   请在下面编辑script 内容--}}

@endsection
@section('script')
<script src="/{$js_file}"></script>
@endsection
text;
      $html_file=resource_path($html_file);
      // 写入文件，存在的话覆盖写入
      File::replace(($html_file), $makecontent);
  }

    /**生成js
     * @param $js_file
     * @param $js_filename
     * @param $middjs
     */
    private static function make_js($js_file,$js_filename,$middjs){


        $makecontent=<<<text
//详情页暂无逻辑
/*
var $, form;
layui.use(['form'], function () {
    $ = layui.$
        , form = layui.form;
    var id = getPar('id');
    if(id>0){
    layer.load(1)
        $.ajax({
            url: './info',
            type: 'GET',
            data: {id: id},
            success: function (result) {
                if (result.code == 200) {

                } else {
                    layer.msg(result.message)
                }
                layer.closeAll();
            }
        });
    }

})
*/
text;

        // 写入文件，存在的话覆盖写入
        File::replace($js_file, $makecontent);
    }


}
